﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace CustomsSystem.DAL
{
    /// <summary>
    /// 数据访问类:feeType
    /// </summary>
    public partial class FeeTypeService
    {
        public FeeTypeService()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string feeTypeNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Info_feeType");
            strSql.Append(" where feeTypeNo=@feeTypeNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@feeTypeNo", SqlDbType.VarChar,10)			};
            parameters[0].Value = feeTypeNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(CustomsSystem.Model.Info_feeType model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Info_feeType(");
            strSql.Append("feeTypeNo,feeName,feeType)");
            strSql.Append(" values (");
            strSql.Append("@feeTypeNo,@feeName,@feeType)");
            SqlParameter[] parameters = {
					new SqlParameter("@feeTypeNo", SqlDbType.VarChar,10),
					new SqlParameter("@feeName", SqlDbType.VarChar,50),
					new SqlParameter("@feeType", SqlDbType.Int,4)};
            parameters[0].Value = model.feeTypeNo;
            parameters[1].Value = model.feeName;
            parameters[2].Value = model.feeType;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CustomsSystem.Model.Info_feeType model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Info_feeType set ");
            strSql.Append("feeName=@feeName,");
            strSql.Append("feeType=@feeType");
            strSql.Append(" where feeTypeNo=@feeTypeNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@feeName", SqlDbType.VarChar,50),
					new SqlParameter("@feeType", SqlDbType.Int,4),
					new SqlParameter("@feeTypeNo", SqlDbType.VarChar,10)};
            parameters[0].Value = model.feeName;
            parameters[1].Value = model.feeType;
            parameters[2].Value = model.feeTypeNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string feeTypeNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Info_feeType ");
            strSql.Append(" where feeTypeNo=@feeTypeNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@feeTypeNo", SqlDbType.VarChar,10)			};
            parameters[0].Value = feeTypeNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string feeTypeNolist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Info_feeType ");
            strSql.Append(" where feeTypeNo in (" + feeTypeNolist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CustomsSystem.Model.Info_feeType GetModel(string feeTypeNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 feeTypeNo,feeName,feeType from Info_feeType ");
            strSql.Append(" where feeTypeNo=@feeTypeNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@feeTypeNo", SqlDbType.VarChar,10)			};
            parameters[0].Value = feeTypeNo;

            CustomsSystem.Model.Info_feeType model = new CustomsSystem.Model.Info_feeType();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["feeTypeNo"] != null && ds.Tables[0].Rows[0]["feeTypeNo"].ToString() != "")
                {
                    model.feeTypeNo = ds.Tables[0].Rows[0]["feeTypeNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["feeName"] != null && ds.Tables[0].Rows[0]["feeName"].ToString() != "")
                {
                    model.feeName = ds.Tables[0].Rows[0]["feeName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["feeType"] != null && ds.Tables[0].Rows[0]["feeType"].ToString() != "")
                {
                    model.feeType = int.Parse(ds.Tables[0].Rows[0]["feeType"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select feeTypeNo,feeName,feeType=case feeType when 0 then '使用' when 1 then '禁用' end  ");
            strSql.Append(" FROM Info_feeType ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" feeTypeNo,feeName,feeType ");
            strSql.Append(" FROM Info_feeType ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Info_feeType ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.feeTypeNo desc");
            }
            strSql.Append(")AS Row, T.*  from Info_feeType T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

      
       


     


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CustomsSystem.Model.Info_feeType DataRowToModel(DataRow row)
        {
            CustomsSystem.Model.Info_feeType model = new CustomsSystem.Model.Info_feeType();
            if (row != null)
            {
                if (row["feeTypeNo"] != null)
                {
                    model.feeTypeNo = row["feeTypeNo"].ToString();
                }
                if (row["feeName"] != null)
                {
                    model.feeName = row["feeName"].ToString();
                }
               
            }
            return model;
        }

   
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetFeeList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select feetypeno,REPLICATE('--',LEN(feetypeNo))+feeName [feeName] ,feetype from Info_feeType ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
          
            return DbHelperSQL.Query(strSql.ToString());
        }
       
     

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

